[#ftl]
[#--include "../../util.ftl"/--]
[#include "MenuBarItem.ftl"/]
[#include "Menu.ftl"/]

[@define "agile.dijit.MenuBar" "agile._Component,agile._Container,agile._Resizable,agile._ContainerToolbar" "MenuBar=dijit/MenuBar,MenuBarItem=dijit/MenuBarItem,PopupMenuBarItem=dijit/PopupMenuBarItem"]
	widgetName:"MenuBar"
	[#assign templateString][#compress]
		<div class='agileComponent agileMenuBar'>
			<div style="width:100%;height:100%" data-dojo-attach-point="containerNode"></div>			
		</div>
	[/#compress][/#assign]
	,templateString:"${templateString?js_string}"	
	,sortAxis:"x"
	,resizeAxis:"x"	
	,autoAdjustChildren:true
	,initDefaultMetadata:function(){
		this.metadata("dojoDeclaredClass","dijit/MenuBar");
		this.metadata("style.width","300px");
		this.metadata("style.height","25px");
	}
//	,constructor: function(){
//		agile.requireX("dijit.MenuBar");
//		agile.requireX("dijit.MenuBarItem");
//		agile.requireX("dijit.PopupMenuBarItem");
//	}
	,init:function(){
		if(this._initMenuBar) return; this._initMenuBar=true;
		
		style.set(this.domNode,{width:null,height:null});
		array.forEach(this._getChildren(),function(child){
			child.metadata("style.height",this.metadata("style.height"));
		},this);
		domClass.add(this.domNode,"dijitMenuBar");
		this.showControlButtons();				
	}
	,showControlButtons:function(child){
		if(child){
			//style.set(this.removeButton,{display:"none"});	
			style.set(this.removeButton,{display:"inline",position:"absolute",right:"5px"});						
			construct.place(this.removeButton,child.getToolbarAnchorNode(),"last");
			this.selectedChild = child;
		}else{
			style.set(this.removeButton,{display:"none"});	
			style.set(this.addButton,{display:"inline",position:"absolute"});						
			construct.place(this.addButton,this.getToolbarAnchorNode(),"last");
		}
	}
	,_getDelegatePrototype:function(){
		return dijit.MenuBar.prototype;
	}
	,getToolbarAnchorNode:function(){
		return this.domNode;
	}
	,getResizableTargetContainer:function(){
		return this.domNode;
	}
	,createChild:function(){
		var child = new agile.dijit.MenuBarItem({label:'File'});
		child.metadata("style.height",this.metadata("style.height"));
		return child;
	}
	,getPreferredSize:function(){
		return {w:100,h:22};
	}
//	,getStyleNodes:function(htmlName){
//		if(htmlName == "left" || htmlName == "top"){
//			return [this.domNode];
//		}	
//		return [this.containerNode];
//	}
	,onResizeStop:function(marginBox){
		this.inherited(arguments);
		style.set(this.containerNode,{width:this.metadata("style.width")});
	}

[/@]	
